package com.ymatou.livevideo.testcase;

import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.livevideo.parameter.RecLiveNotifyBean;
import com.ymatou.livevideo.parameter.StreamLiveNotifyBean;
import com.ymatou.livevideo.service.LiveNotifyCall;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.CounterCallService;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.livetv.ProductVideo;
import com.ymttest.database.model.livetv.ProductVideoExplain;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.RemoteShellExecutor2;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

import org.apache.http.client.ClientProtocolException;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 直播第三方回调通知 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_LiveNotify {
	private static StreamLiveNotifyBean streamlivenotifyBean;
	private static LiveNotifyCall livenotifyCall;
	private static LiveRoomWapper liveroomwapper;
	private static RecLiveNotifyBean recivenotifyBean;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("直播第三方回调通知");
	}

	@Before
	public void caseUp() {
		streamlivenotifyBean = new StreamLiveNotifyBean();
		livenotifyCall = new LiveNotifyCall();
		liveroomwapper = new LiveRoomWapper();
		recivenotifyBean = new RecLiveNotifyBean();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(livenotifyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_001() {
		Logger.start(true, "直播第三方回调通知成功推流");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			if(livenotifyCall.getString("code").equals("500")) {
				TestDataManager.RunYumUpdate("172.16.101.120", "root", "ymt@123");
				livenotifyCall.callService();
			}
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(2, dbliveroom.getLiveStatus(), "验证LiveStatus");
			Logger.verifyEquals(1, dbliveroom.getLivePush(), "验证LivePush");
			verifyPushStream(liveroom.getId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_002() {
		Logger.start(true, "直播第三方回调通知成功断流");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再断流");
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			verifyPushStream(liveroom.getId());
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(3, dbliveroom.getLiveStatus(), "验证LiveStatus");
			Logger.verifyEquals(1, dbliveroom.getLivePush(), "验证LivePush");
			verifyAbortStream(liveroom.getId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_003() {
		Logger.start(true, "直播第三方回调通知成功新的录制文件已生成");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			livenotifyCall.setData(recivenotifyBean);
			
			Map mock=new HashMap();
//			mock:mock-enable
			mock.put("mock", "mock-enable");
			mock.put("mockId-1", TestDataManager.getRandomUUID().toString());
			mock.put("mockApi-1", "livevideo-processMediaByProcedure-Normal");
			PayGateWayCallService.addMock(livenotifyCall, mock);
			
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(recivenotifyBean.getVideo_url(), dbliveroom.getHistoryPlayUrl(), "验证getHistoryPlayUrl");
			Map m = liveroomwapper.selectLivereplayById(dbliveroom.getId().toString());
			Logger.verifyEquals(recivenotifyBean.getFile_id(), m.get("FileId").toString(), "验证FileId");
			Logger.verifyEquals(recivenotifyBean.getDuration(), m.get("ReplayTime").toString(), "验证ReplayTime");
			Logger.verifyEquals(recivenotifyBean.getVideo_url(), m.get("ReplayUrl").toString(), "验证ReplayUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	@Ignore
	public void Tc_LiveNotify_004() {
		Logger.start(true, "直播第三方回调通知成功新的截图文件已生成");
		try {
			// TODO 补全case代码
			org.junit.Assert.fail();
			// livenotifyCall.setData(livenotifyBean);
			livenotifyCall.callService();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_005() {
		Logger.start(true, "签名错误失败");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			streamlivenotifyBean.setSign("1");
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("500", livenotifyCall.getString("code"), "验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_006() {
		Logger.start(true, "未推流直播第三方回调通知成功断流,状态不变0->0");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(0, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_007() {
		Logger.start(true, "系统自动关闭直播7不再接受直播第三方回调通知成功推流变更");
		try {
			int updatestatus = 7;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_008() {
		Logger.start(true, "系统自动关闭直播7不再接受直播第三方回调通知成功断流变更");
		try {
			int updatestatus = 7;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_009() {
		Logger.start(true, "直播第三方回调通知成功断流再推流成功");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再断流再推流");
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			verifyPushStream(liveroom.getId());
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			verifyAbortStream(liveroom.getId());
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			verifyPushStream(liveroom.getId());
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(2, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_010() {
		Logger.start(true, "关闭直播8不再接受直播第三方回调通知成功推流变更");
		try {
			int updatestatus = 8;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_011() {
		Logger.start(true, "结束直播9不再接受直播第三方回调通知成功推流变更");
		try {
			int updatestatus = 9;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_012() {
		Logger.start(true, "强制关停10不再接受直播第三方回调通知成功推流变更");
		try {
			int updatestatus = 10;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_013() {
		Logger.start(true, "关闭直播8不再接受直播第三方回调通知成功断流变更");
		try {
			int updatestatus = 8;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_014() {
		Logger.start(true, "结束直播9不再接受直播第三方回调通知成功断流变更");
		try {
			int updatestatus = 9;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_015() {
		Logger.start(true, "强制关停10不再接受直播第三方回调通知成功断流变更");
		try {
			int updatestatus = 10;
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			liveroomwapper.updateLiveRoomPushStatus(liveroom.getId(), updatestatus);

			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(updatestatus, dbliveroom.getLiveStatus(), "验证LiveStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_016() {
		Logger.start(true, "直播第三方回调通知成功新的录制文件已生成-第二次ReplayTime大于第一次更新记录");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			livenotifyCall.setData(recivenotifyBean);
			Map mock=new HashMap();
//			mock:mock-enable
			mock.put("mock", "mock-enable");
			mock.put("mockId-1", TestDataManager.getRandomUUID().toString());
			mock.put("mockApi-1", "livevideo-processMediaByProcedure-Normal");
			PayGateWayCallService.addMock(livenotifyCall, mock);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(recivenotifyBean.getVideo_url(), dbliveroom.getHistoryPlayUrl(), "验证getHistoryPlayUrl");
			Map m = liveroomwapper.selectLivereplayById(dbliveroom.getId().toString());
			Logger.verifyEquals(recivenotifyBean.getFile_id(), m.get("FileId").toString(), "验证FileId");
			Logger.verifyEquals(recivenotifyBean.getDuration(), m.get("ReplayTime").toString(), "验证ReplayTime");
			Logger.verifyEquals(recivenotifyBean.getVideo_url(), m.get("ReplayUrl").toString(), "验证ReplayUrl");
			
			recivenotifyBean.setFile_size(1+recivenotifyBean.getFile_size());
			recivenotifyBean.setDuration(1+recivenotifyBean.getDuration());
			recivenotifyBean.setFile_id(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
			
			Map mock2=new HashMap();
//			mock:mock-enable
			mock2.put("mock", "mock-enable");
			mock2.put("mockId-1", TestDataManager.getRandomUUID().toString());
			mock2.put("mockApi-1", "livevideo-processMediaByProcedure-Normal");
			PayGateWayCallService.addMock(livenotifyCall, mock2);
			
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(recivenotifyBean.getVideo_url(), dbliveroom.getHistoryPlayUrl(), "验证getHistoryPlayUrl");
			m = liveroomwapper.selectLivereplayById(dbliveroom.getId().toString());
			Logger.debug(m);
			Logger.verifyEquals(recivenotifyBean.getFile_id(), m.get("FileId").toString(), "验证FileId");
			Logger.verifyEquals(recivenotifyBean.getDuration(), m.get("ReplayTime").toString(), "验证ReplayTime");
			Logger.verifyEquals(recivenotifyBean.getVideo_url(), m.get("ReplayUrl").toString(), "验证ReplayUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_017() {
		Logger.start(true, "直播第三方回调通知成功新的录制文件已生成-第二次ReplayTime小于第一次不更新记录");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			livenotifyCall.setData(recivenotifyBean);
			
			Map mock2=new HashMap();
//			mock:mock-enable
			mock2.put("mock", "mock-enable");
			mock2.put("mockId-1", TestDataManager.getRandomUUID().toString());
			mock2.put("mockApi-1", "livevideo-processMediaByProcedure-Normal");
			PayGateWayCallService.addMock(livenotifyCall, mock2);
			
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(recivenotifyBean.getVideo_url(), dbliveroom.getHistoryPlayUrl(), "验证getHistoryPlayUrl");
			Map m = liveroomwapper.selectLivereplayById(dbliveroom.getId().toString());
			Logger.verifyEquals(recivenotifyBean.getFile_id(), m.get("FileId").toString(), "验证FileId");
			Logger.verifyEquals(recivenotifyBean.getDuration(), m.get("ReplayTime").toString(), "验证ReplayTime");
			Logger.verifyEquals(recivenotifyBean.getVideo_url(), m.get("ReplayUrl").toString(), "验证ReplayUrl");
			
			String ofid=recivenotifyBean.getFile_id();
			String ofrt=recivenotifyBean.getDuration();
			String ofurl=recivenotifyBean.getVideo_url();
			recivenotifyBean.setFile_size("1");
			recivenotifyBean.setDuration("1");
			recivenotifyBean.setFile_id(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
			Map mock=new HashMap();
//			mock:mock-enable
			mock.put("mock", "mock-enable");
			mock.put("mockId-1", TestDataManager.getRandomUUID().toString());
			mock.put("mockApi-1", "livevideo-processMediaByProcedure-Normal");
			PayGateWayCallService.addMock(livenotifyCall, mock);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(recivenotifyBean.getVideo_url(), dbliveroom.getHistoryPlayUrl(), "验证getHistoryPlayUrl");
			m = liveroomwapper.selectLivereplayById(dbliveroom.getId().toString());
			Logger.debug(m);
			Logger.verifyEquals(ofid, m.get("FileId").toString(), "验证FileId");
			Logger.verifyEquals(ofrt, m.get("ReplayTime").toString(), "验证ReplayTime");
			Logger.verifyEquals(ofurl, m.get("ReplayUrl").toString(), "验证ReplayUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_018() {
		Logger.start(true, "直播录制回调生成文件，生成之后，视频表会新增数据，状态为5");
		try {
			int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			Date starttime = new Date(now.getTime() + 4000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(clive);
			LiveRoomCallService.AddProductsToLive(livedto.getId(), sellerId, productId);
			Thread.sleep(5000);
			LiveRoomCallService.SellerLiveOnline(livedto.getId(), livedto.getUserId());
			String taskId = LiveRoomCallService.CreateProductVideo(livedto.getId(), sellerId, productId);
			LiveRoomCallService.StopProductVideo(livedto.getId(), productId);
			recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(livedto.getId(), 100);
			recivenotifyBean.setTask_id(taskId);
			String fileId = TestDataManager.getRandomNum(15);
			recivenotifyBean.setFile_id(fileId);
			livenotifyCall.setData(recivenotifyBean);
			Map mock=new HashMap();
//			mock:mock-enable
			mock.put("mock", "mock-enable");
			mock.put("mockId-1", TestDataManager.getRandomUUID().toString());
			mock.put("mockApi-1", "livevideo-processMediaByProcedure-Normal");
			PayGateWayCallService.addMock(livenotifyCall, mock);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			ProductVideo pv = liveroomwapper.selectProductvideo(productId);
			Logger.verifyEquals(pv.getUserId(),sellerId , "验证UserId");
			Logger.verifyEquals(pv.getVideoUrl(),recivenotifyBean.getVideo_url() , "验证VideoUrl");
			Logger.verifyEquals(pv.getDuration()+"",recivenotifyBean.getDuration() , "验证Duration");
			Logger.verifyEquals(pv.getVideoSize()+"",recivenotifyBean.getFile_size() , "验证VideoSize");
			Logger.verifyEquals(pv.getTaskId()+"",taskId , "验证TaskId");
			Logger.verifyEquals(pv.getFileId(),recivenotifyBean.getFile_id() , "验证FileId");
			
			ProductVideoExplain pve = liveroomwapper.selectProductvideoExplain(productId);
			Logger.verifyEquals(pve.getUserId(),sellerId , "验证UserId");
			Logger.verifyEquals(pve.getTaskId()+"",taskId , "验证TaskId");
			Logger.verifyEquals(pve.getLiveId(),livedto.getId() , "验证LiveId");
			Logger.verifyEquals(pve.getExplainStatus(),5, "验证ExplainStatus");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_LiveNotify_019() {
		Logger.start(true, "第一次录制成功回调之后，第二次再创建录制、如果取消录制，就恢复第一次的状态");
		try {
			int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			Date starttime = new Date(now.getTime() + 4000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(clive);
			LiveRoomCallService.AddProductsToLive(livedto.getId(), sellerId, productId);
			Thread.sleep(5000);
			LiveRoomCallService.SellerLiveOnline(livedto.getId(), livedto.getUserId());
			String taskId = LiveRoomCallService.CreateProductVideo(livedto.getId(), sellerId, productId);
			LiveRoomCallService.StopProductVideo(livedto.getId(), productId);
			recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(livedto.getId(), 100);
			recivenotifyBean.setTask_id(taskId);
			String fileId = TestDataManager.getRandomNum(15);
			recivenotifyBean.setFile_id(fileId);
			livenotifyCall.setData(recivenotifyBean);
			Map mock=new HashMap();
//			mock:mock-enable
			mock.put("mock", "mock-enable");
			mock.put("mockId-1", TestDataManager.getRandomUUID().toString());
			mock.put("mockApi-1", "livevideo-processMediaByProcedure-Normal");
			PayGateWayCallService.addMock(livenotifyCall, mock);
			livenotifyCall.callService();
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			ProductVideo pv = liveroomwapper.selectProductvideo(productId);
			Logger.verifyEquals(pv.getUserId(),sellerId , "验证UserId");
			Logger.verifyEquals(pv.getVideoUrl(),recivenotifyBean.getVideo_url() , "验证VideoUrl");
			Logger.verifyEquals(pv.getDuration()+"",recivenotifyBean.getDuration() , "验证Duration");
			Logger.verifyEquals(pv.getVideoSize()+"",recivenotifyBean.getFile_size() , "验证VideoSize");
			Logger.verifyEquals(pv.getTaskId()+"",taskId , "验证TaskId");
			Logger.verifyEquals(pv.getFileId(),recivenotifyBean.getFile_id() , "验证FileId");
			
			ProductVideoExplain pve = liveroomwapper.selectProductvideoExplain(productId);
			Logger.verifyEquals(pve.getUserId(),sellerId , "验证UserId");
			Logger.verifyEquals(pve.getTaskId()+"",taskId , "验证TaskId");
			Logger.verifyEquals(pve.getLiveId(),livedto.getId() , "验证LiveId");
			Logger.verifyEquals(pve.getExplainStatus(),5, "验证ExplainStatus");
			//第二次创建录制,如果取消录制，状态会和第一次一样
			String taskId1 = LiveRoomCallService.CreateProductVideo(livedto.getId(), sellerId, productId);
			LiveRoomCallService.RemoveProductVideo(livedto.getId(), productId);
			pv = liveroomwapper.selectProductvideo(productId);
			Logger.verifyEquals(pv.getUserId(),sellerId , "验证UserId");
			Logger.verifyEquals(pv.getVideoUrl(),recivenotifyBean.getVideo_url() , "验证VideoUrl");
			Logger.verifyEquals(pv.getDuration()+"",recivenotifyBean.getDuration() , "验证Duration");
			Logger.verifyEquals(pv.getVideoSize()+"",recivenotifyBean.getFile_size() , "验证VideoSize");
			Logger.verifyEquals(pv.getTaskId()+"",taskId , "验证TaskId");
			Logger.verifyEquals(pv.getFileId(),recivenotifyBean.getFile_id() , "验证FileId");
			pve = liveroomwapper.selectProductvideoExplain(productId);
			System.out.println(pve);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LiveNotify_020() {
		Logger.start(true, "直播第三方回调通知成功推流、计数器+1");
		try {
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再断流");
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 1);
			livenotifyCall.setData(streamlivenotifyBean);
			livenotifyCall.callService();
			verifyPushStream(liveroom.getId());
			streamlivenotifyBean = LiveRoomCallService.initStreamLiveNotifyBean(liveroom.getId(), 0);
			livenotifyCall.setData(streamlivenotifyBean);

			Integer counter = CounterCallService.getSingleValueByLiveId(liveroom.getId());
			livenotifyCall.callService();	
			Integer counter1 = CounterCallService.getSingleValueByLiveId(liveroom.getId());
			Logger.verifyEquals(counter+1, counter1, "添加商品之后，计数器+1");
			
			Logger.verifyEquals("0", livenotifyCall.getString("code"), "验证code");
			LiveRoom dbliveroom = liveroomwapper.selectLiveRoomById(liveroom.getId());
			Logger.verifyEquals(3, dbliveroom.getLiveStatus(), "验证LiveStatus");
			Logger.verifyEquals(1, dbliveroom.getLivePush(), "验证LivePush");
			verifyAbortStream(liveroom.getId());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	
	private void verifyPushStream(Integer liveId) throws ClientProtocolException, IOException, InterruptedException {
		Logger.comment("验证总线发送消息");
		MessageListBean MessageListBean = MqQueryCallService.initSteamSync(liveId);
		List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
		int redo=0;
		while(joa.size()==0&&redo<5){
			redo++;
			Thread.sleep(5000);
			joa = MqQueryCallService.GetMqMessage(MessageListBean);
		}
		//Logger.verifyEquals(1, joa.size(), "验证发送总线消息");
		Logger.verifyEquals(liveId.toString(),joa.get(0).get("LiveId").toString(), "验证liveId");
		Thread.sleep(5000);
		LiveRoom createLive = new LiveRoomWapper().selectLiveRoomById(liveId);
		Integer status = createLive.getLiveStatus();
		Logger.verifyEquals(2, status, "验证status为2");
	}
	private void verifyAbortStream(Integer liveId) throws ClientProtocolException, IOException, InterruptedException {
		Logger.comment("验证总线发送消息");
		MessageListBean MessageListBean = MqQueryCallService.initSteamSync(liveId);
		List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
		int redo=0;
		while(joa.size()==0&&redo<5){
			redo++;
			Thread.sleep(5000);
			joa = MqQueryCallService.GetMqMessage(MessageListBean);
		}
		//Logger.verifyEquals(2, joa.size(), "验证发送总线消息");
		Logger.verifyEquals(liveId.toString(),joa.get(0).get("LiveId").toString(), "验证liveId");
		Thread.sleep(5000);
		LiveRoom createLive = new LiveRoomWapper().selectLiveRoomById(liveId);
		Integer status = createLive.getLiveStatus();
		Logger.verifyEquals(3, status, "验证status为3");
	}
}